//*******************************//
//<xml fileName="ConnectionHelper.java" ?>
//<author>申鱼川</author>
//<dateTime>2014-02-23</dateTime>
//</xml>
//*******************************//
package ccgl.com.factory;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import ccgl.com.util.ParamConfigParameters;

/**
 * 连接helper
 * 
 * @author Administrator
 * 
 */
public class ConnectionFactory {
	/*
	 * 数据库连接
	 */
	private static Connection conn = null;

	/**
	 * 根据库名得到连接
	 * 
	 * @return 返回连接对象
	 */
	public static Connection getConnection() {
		ParamConfigParameters params = null;
		try {
			params = new ParamConfigParameters();
			Class.forName(params.getParameter("driver-class"));
			conn = DriverManager.getConnection(
					params.getParameter("driver-url"),
					params.getParameter("user"),
					params.getParameter("password"));
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			params.closeResource();
		}

		return conn;
	}
	
	public static void main(String[] args) {
		Connection con = ConnectionFactory.getConnection();
		System.out.println(con == null);
		try {
			con.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
